
package logic.beans;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(
		name="FOODCOMPONENTS",
		uniqueConstraints={ @UniqueConstraint(columnNames={ "name","percentage" }) })
public class FoodComponent implements DBElementIF {
	private static final long serialVersionUID = 6943809730699499076L;
	
	private String name;
	private float percentage;
	private Long id;
	
	public FoodComponent() {
		this("",0);
	}
	
	public FoodComponent(String name,float percentage) {
		setName(name);
		setPercentage(percentage);
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@Column(nullable=false)
	public String getName() {
		return name;
	}
	
	public void setPercentage(float percentage) {
		this.percentage = percentage;
	}
	
	@Column(nullable=false)
	public float getPercentage() {
		return percentage;
	}
	
	@SuppressWarnings("unused")
	private void setId(Long id) {
		this.id = id;
	}
	
	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}
	
	@Override
	public String toString() {
		return getName() + " - " + getPercentage();
	}
}
